package com.tg.service.suzakuEventBus.definition;

import com.google.common.collect.Lists;
import com.tg.service.suzakuEventBus.config.EngineEventConfig;
import com.tg.service.suzakuEventBus.handler.TaskEventHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.DependsOn;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

import java.util.ArrayList;

/**
 * Created by linzc on 2018/9/20.
 */
public class FooImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {

    @Autowired
    private EngineEventConfig eventConfig;

    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {


        ArrayList<String> list = Lists.newArrayList("Login", "Invest");

        for (String eventName : list) {
            BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(TaskEventHandler.class);
            BeanDefinition beanDefinition = builder.getBeanDefinition();
            beanDefinition.setAutowireCandidate(true);
            beanDefinition.setLazyInit(false);

            registry.registerBeanDefinition(eventName + TaskEventHandler.class.getSimpleName(), beanDefinition);
        }
    }
}
